import { Controller, Get, Post, Body } from '@nestjs/common';
import { ProjectsService } from './projects.service';
import { Project } from '../entities/project.entity';
import { createResponse } from '../common/response.interface';
import type { IResponse } from '../common/response.interface';

@Controller('api/projects')
export class ProjectsController {
  constructor(private readonly projectsService: ProjectsService) {}

  @Get()
  async findAll(): Promise<IResponse<Project[]>> {
    const projects = await this.projectsService.findAll();
    return createResponse(projects);
  }

  @Post()
  async create(
    @Body()
    createProjectDto: {
      projectName: string;
      description?: string;
      owner?: string;
    },
  ): Promise<IResponse<Project>> {
    const project = await this.projectsService.create(createProjectDto);
    return createResponse(project, '项目创建成功');
  }
}